<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动态渐变边框示例</title>
    <style>
        body {
            margin: 0;
            padding: 40px;
            background-color: #1a1a1a;
            font-family: Arial, sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .title {
            color: #fff;
            text-align: center;
            margin-bottom: 30px;
            font-size: 24px;
            font-weight: bold;
        }

        /* 父容器样式 */
        .parent-container {
            width: 80%;
            max-width: 800px;
            background-color: rgba(0, 0, 0, 0.3);
            padding: 20px;
            margin-bottom: 40px;
            resize: both; /* 允许用户调整大小 */
            overflow: auto;
            min-width: 300px;
            min-height: 200px;
        }

        .resize-hint {
            color: #0082FF;
            font-size: 14px;
            margin-bottom: 10px;
            text-align: center;
        }

        /* 方法一：SVG实现边框渐变 */
        .gradient-border-svg {
            position: relative;
            width: 100%;
            height: 100%;
            min-height: 150px;
        }

        .content-box {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 18px;
            z-index: 1;
        }

        .svg-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 0;
        }

        /* 方法二：使用CSS线性渐变 */
        .gradient-border-css {
            width: 100%;
            height: 100%;
            min-height: 150px;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 18px;
        }

        .gradient-border-css::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            border: 1px solid transparent;
            border-image: linear-gradient(to bottom, #0082FF, rgba(0, 178, 213, 0.1)) 1;
            pointer-events: none;
        }

        /* 方法三：使用多个div元素 */
        .gradient-border-div {
            width: 100%;
            height: 100%;
            min-height: 150px;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 18px;
        }

        .border-top {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 1px;
            background-color: #0082FF;
        }

        .border-right {
            position: absolute;
            top: 0;
            right: 0;
            width: 1px;
            height: 100%;
            background: linear-gradient(to bottom, #0082FF, rgba(0, 178, 213, 0.1));
        }

        .border-bottom {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 1px;
            background-color: rgba(0, 178, 213, 0.1);
        }

        .border-left {
            position: absolute;
            top: 0;
            left: 0;
            width: 1px;
            height: 100%;
            background: linear-gradient(to bottom, #0082FF, rgba(0, 178, 213, 0.1));
        }

        .method-title {
            color: #0082FF;
            font-size: 18px;
            margin-bottom: 15px;
            text-align: center;
        }

        /* 线下大厅应用示例 */
        .application-example {
            width: 80%;
            max-width: 800px;
            margin-top: 50px;
        }

        .example-title {
            color: #fff;
            font-size: 20px;
            margin-bottom: 20px;
            text-align: center;
        }

        .realTimeOverviewMain {
            position: relative;
            padding: 15px;
            height: 300px;
            margin-top: 8px;
            margin-bottom: 43px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            background-color: rgba(0, 0, 0, 0.3);
            color: #fff;
        }

        .code-block {
            background-color: #2a2a2a;
            padding: 15px;
            border-radius: 5px;
            margin-top: 20px;
            overflow-x: auto;
            color: #ddd;
            font-family: monospace;
            font-size: 14px;
            line-height: 1.5;
        }
    </style>
</head>
<body>
    <div class="title">动态渐变边框示例（相对于父容器）</div>
    
    <!-- 方法一：SVG实现 -->
    <div class="method-title">方法一：SVG实现（最精确）</div>
    <div class="resize-hint">可拖动右下角调整大小</div>
    <div class="parent-container">
        <div class="gradient-border-svg">
            <div class="content-box">SVG渐变边框</div>
            <svg class="svg-container" preserveAspectRatio="none" viewBox="0 0 100 100">
                <defs>
                    <linearGradient id="borderGradient1" x1="0%" y1="0%" x2="0%" y2="100%">
                        <stop offset="0%" style="stop-color:#0082FF" />
                        <stop offset="100%" style="stop-color:#00B2D5;stop-opacity:0.1" />
                    </linearGradient>
                </defs>
                <rect x="0.5" y="0.5" width="99" height="99" fill="none" stroke="url(#borderGradient1)" stroke-width="1"/>
            </svg>
        </div>
    </div>

    <!-- 方法二：CSS线性渐变 -->
    <div class="method-title">方法二：CSS border-image实现</div>
    <div class="resize-hint">可拖动右下角调整大小</div>
    <div class="parent-container">
        <div class="gradient-border-css">
            CSS渐变边框
        </div>
    </div>

    <!-- 方法三：多个div元素 -->
    <div class="method-title">方法三：多个div元素实现</div>
    <div class="resize-hint">可拖动右下角调整大小</div>
    <div class="parent-container">
        <div class="gradient-border-div">
            <div class="border-top"></div>
            <div class="border-right"></div>
            <div class="border-bottom"></div>
            <div class="border-left"></div>
            DIV渐变边框
        </div>
    </div>

    <!-- 线下大厅应用示例 -->
    <div class="application-example">
        <div class="example-title">线下大厅应用示例</div>
        <div class="realTimeOverviewMain">
            <svg class="svg-container" preserveAspectRatio="none" viewBox="0 0 100 100">
                <defs>
                    <linearGradient id="borderGradient2" x1="0%" y1="0%" x2="0%" y2="100%">
                        <stop offset="0%" style="stop-color:#0082FF" />
                        <stop offset="100%" style="stop-color:#00B2D5;stop-opacity:0.1" />
                    </linearGradient>
                </defs>
                <rect x="0.5" y="0.5" width="99" height="99" fill="none" stroke="url(#borderGradient2)" stroke-width="1"/>
            </svg>
            <div>线下大厅内容区域</div>
        </div>

        <div class="code-block">
            <pre>&lt;!-- 在线下大厅.html中的应用 --&gt;
&lt;div class="realTimeOverviewMain p-[15px] h-[480px] mt-[8px] mb-[43px] flex flex-col justify-between"&gt;
    &lt;svg class="svg-container" preserveAspectRatio="none" viewBox="0 0 100 100"&gt;
        &lt;defs&gt;
            &lt;linearGradient id="borderGradient" x1="0%" y1="0%" x2="0%" y2="100%"&gt;
                &lt;stop offset="0%" style="stop-color:#0082FF" /&gt;
                &lt;stop offset="100%" style="stop-color:#00B2D5;stop-opacity:0.1" /&gt;
            &lt;/linearGradient&gt;
        &lt;/defs&gt;
        &lt;rect x="0.5" y="0.5" width="99" height="99" fill="none" stroke="url(#borderGradient)" stroke-width="1"/&gt;
    &lt;/svg&gt;
    &lt;!-- 其他内容 --&gt;
&lt;/div&gt;</pre>
        </div>

        <div class="code-block">
            <pre>/* 需要添加的CSS样式 */
.realTimeOverviewMain {
    position: relative;
}

.svg-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}</pre>
        </div>
    </div>

    <div style="color: #fff; text-align: center; margin-top: 30px; font-size: 14px;">
        <p>动态渐变边框实现要点：</p>
        <p>1. 将容器宽高设置为100%，使其填充父元素</p>
        <p>2. SVG方法中使用preserveAspectRatio="none"确保SVG可以任意拉伸</p>
        <p>3. 使用相对单位的viewBox（如0 0 100 100）使计算更简单</p>
        <p>4. 确保父容器设置了position: relative</p>
    </div>
</body>
</html>